<include file="public@header" />
</head>

<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<?php $currentTab = 4 ;?>
			<include file="public/../company/nav" />
		</ul>   

		<form class="well form-inline margin-top-20" method="post" action="">
			<label>当前访问源外网ip地址：{$ipInfo.current_ip|default='未获取到~'}</label><br/>
			<label>备份源ip地址：{$ipInfo.addr|default='无更新~'}  上次更新时间：<?php if( empty($ipInfo['bak_time']) ){ echo '无更新~';}else{echo date('Y-m-d H:i:s',$ipInfo['bak_time']);}?> </label>
        </form>    

        <table class="table table-bordered table-hover" style="text-align: center;">
        	<thead>
        		<tr>
        			<th width="300" style="text-align: center;" >公司名称</th> 
                    <th width="60" style="text-align: center;">到期时间</th>
                    <th style="text-align: center;">接口域名地址</th>
        			<th style="text-align: center;" >状态</th>
        			<th width="300" style="text-align: center;" >操作</th>
        		</tr>
        	</thead>
        	<tbody>
                <volist name="companyList" id="vo">
	        		<tr>
	        			<td>{$vo.company_name}</td>
	        			<td>{:date('Y/m/d' , $vo [ 'period' ] )}</td>
	        			<td style="text-align: center;word-wrap:break-word;word-break:break-all;">{$vo.commicate_addr|default='-'}</td>
	        			<td>
							<p style="color:{$vo.source_status_color}" >源码：{$vo.bak_source_time|default="-"}|{$vo.bak_source_stus}</p>
							<p  style="color:{$vo.database_status_color}" >数据 ：{$vo.bak_db_time|default="-"}|{$vo.bak_db_stus}</p>
						</td>
	        			<td>
	        				<a href="javascript:;" class="btn btn-warning btn-xs" title="目标备份系统通信地址." data-addrapi="{$vo.commicate_addr|default=''}" onclick="setAddress( this , {$vo.id} , '{$vo.company_name}');">地址</a>
							<if condition="!empty($vo['addr_source'])">
								<a href="javascript:;" class="btn btn-success btn-xs" onclick="backupWindow( this , '{$vo.addr_source}' , {$vo.id} ,'{$vo.company_name}');" >备份源码</a>
							</if>
	        				<if condition="!empty($vo['addr_db'])">
								<a href="{:url('admin/companyBackup/backupDb',['id'=>$vo['id'] ])}" class="btn btn-success btn-xs zy-ajax-confirm"  data-msg='是否为({$vo.company_name})的数据库安全备份?' >备份数据库</a>
							</if>
							<a href="javascript:;" class="btn btn-info btn-xs" onclick="showBakRecord({$vo.id} , '{$vo.company_name}' );">备份记录</a>
	        			</td>
	        		</tr>
	            </volist>
        	</tbody>
        </table>
		
		<div class="pagination">{$companyList->render()}</div>
	</div>

	
    <script src="__STATIC__/js/layer/layer.js"></script>
    <script src="__STATIC__/js/custom/custom.js"></script>
<script>
	var operateStatus = null ;
	//设置通信地址
	var setAddress = function ( _this , id  , name )
	{
		let addr_api = $(_this).data( 'addrapi' );
		layer.open({
			type: 2,
			title: name+'通信地址配置',
			btn:['保存','取消'],
			closeBtn: 0,
			area: [ '500px' , '200px' ],
			shadeClose: true,
			skin: 'yourclass',
			content: '{:url("admin/companyBackup/commicateAddr")}?addr_api='+addr_api,
			yes:function( index ){
				var res = window["layui-layer-iframe" + index].getData();
				let addr_api = res.addr_api;
				let url = "{:url('admin/companyBackup/editeCommicateAddr')}";
				$.post( url , { id : id , addr_api : addr_api } , function(data){
					let icon = ( data.code == 200 ) ?  1 : 5;
					layer.msg( data.message , { icon : icon } );
					if( icon == 1 ){
						setTimeout( function(){
							window.location.reload();
						} , 1200);
					}	
				} , 'json' );
			}
		});
	}

	//备份窗口
	var backupWindow = function( _this , commicateAddr , companyId , companyName ){
		if( $.trim( commicateAddr ).lenght == 0  ){
			layer.msg( '请求地址为添加!' , { icon : 5 } );
			return false;
		}
		console.log( commicateAddr );
		var openddd = layer.open({
			type: 2,
			btn: [ '确定' , '关闭' ],
			area: ['95%', '95%'],
			title: companyName+'备份操作',
			fixed: false, //不固定
			maxmin: true,
			content: '{:url("admin/companyBackup/backupList")}?id='+companyId+"&addr_api="+commicateAddr,
			yes:function( index ){
				var res = window["layui-layer-iframe" + index].saveData();
		
				if( res == -1 ) {
					layer.msg('未选择任何文件，无法操作!',{icon:5});
					return false;
				}
				
				//执行备份操作  添加备份记录
				//action 
				var promptInde = layer.prompt({
					formType: 2,
					title: '备注信息',
					area: ['700px', '200px'] //自定义文本域宽高
				}, function(value, index, elem){
					layer.close(openddd);
					layer.msg(  '操作成功！' , { icon : 1 } );
					let url = "{:url('admin/companyBackup/excuteBackup')}";
					$.post( url , { id : companyId , remarks : value , list : res } , function(data){
						window.location.reload();
						/*let icon = ( data.code == 200 ) ?  1 : 5;
						layer.msg( data.message , { icon : icon } );
						if( icon == 1 ){
							setTimeout( function(){
								layer.closeAll();
							} , 1200 );
						}*/	
					} , 'json' );
					setTimeout(function(){
						layer.close(promptInde);
					},1200);
					
				});
			},
			end:function(){
				window.location.reload();
			}
		});
	}

	//查看记录
	var showBakRecord = function( id , companyName ){
		layer.open({
			type: 2,
			btn: [ '确定' , '取消' ],
			area: ['95%', '95%'],
			title: companyName+'备份记录',
			fixed: false, //不固定
			maxmin: true,
			content: '{:url("admin/companyBackup/recordParticular")}?id='+id,
			end:function(){
				window.location.reload();
			}
		});
	}
</script>
</body>
</html>